In a , you can add hyperlinks in a report using the Hyperlink property available with the following controls:
You can add hyperlinks that connect to a Web page, open an e-mail, or jump to a bookmark.
|
Note: Specify the full URL address (for example, "http://www.grapecity.com") for the Hyperlink property to avoid broken links while viewing reports. |
To link to a Web page
- Select an existing control or drag and drop a control from the Visual Studio toolbox onto the .
- Right-click the control to open the Properties Window.
- In the Properties Window, set the HyperLink property to any valid URL. For example, for example, http://www.grapecity.com.
To link to an e-mail address
- Select an existing control or drag and drop a control from the Visual Studio toolbox onto the design surface.
- Right-click the control to open the Properties Window.
- In the Properties Window, set the HyperLink property to mailto: any valid e-mail address.
To parse the URL out of a database field for a hyperlink
- From the Report Explorer, drag and drop the link field onto the design surface.
- Double-click the section where you had placed the link field. This creates an event-handling method for the section's Format event.
- Add code to the Format event to,
- Parse the URL out of the Link field
- Assign it to the HyperLink property of TextBox
- Remove the URL markers from the text displayed in TextBox
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code
|
Dim iStart As Integer
Dim sHTML As String
If textBox1.Text <> "" Then
iStart = InStr(1, textBox1.Text, "#", CompareMethod.Text)
sHTML = Right(textBox1.Text, (Len(textBox1.Text) - iStart))
sHTML = Replace(sHTML, "#", "", 1, -1, CompareMethod.Text)
textBox1.HyperLink = sHTML
textBox1.Text = Replace(textBox1.Text, "#", "", 1, -1, CompareMethod.Text)
End If
|
To write the code in C#
C# code. Paste INSIDE the Format event. |
Copy Code
|
int iStart;
string sHTML;
if (textBox1.Text != "")
{
iStart = textBox1.Text.IndexOf("#",0);
sHTML = textBox1.Text.Substring(iStart, textBox1.Text.Length - iStart);
sHTML = sHTML.Replace("#", "");
textBox1.HyperLink = sHTML;
textBox1.Text = textBox1.Text.Replace("#", "");
}
|
To create a hyperlink that jumps to a bookmark
- From the Report Explorer, drag and drop a field onto the design surface.
- Double-click the section where you had placed the field. This creates an event-handling method for the section's Format event.
- Add the following code inside the Format event.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste JUST ABOVE the Format event. |
Copy Code
|
Public pBM As New BookmarksCollection()
Dim iEntry As Integer
|
Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code
|
Me.Detail1.AddBookmark(Me.textBox1.Text)
Me.txtEntry.HyperLink = "toc://" + pBM(iEntry - 1).Label
Me.txtEntry.Text = pBM(iEntry - 1).Label
Me.txtPage.Text = pBM(iEntry - 1).PageNumber
|
To write the code in C#
C# code. Paste JUST ABOVE the Format event. |
Copy Code
|
public BookmarksCollection pBM = new BookmarksCollection();
int iEntry;
|
C# code. Paste INSIDE the Format event. |
Copy Code
|
this.detail.AddBookmark(this.textBox.Text);
this.txtEntry.HyperLink = "toc://" + pBM[iEntry - 1].Label;
this.txtEntry.Text = pBM[iEntry - 1].Label;
this.txtPage.Text = pBM[iEntry - 1].PageNumber.ToString();
|
To display the page number of the bookmark in the table of contents
- Select the gray area outside the report and right-click to choose Properties option from the context menu.
- In the Properties Window that appears, click the Events button to get the list of events for the report.
- Select the FetchData event from that list and double-click it. This creates an event-handling method for the report's FetchData event in the code behind.
- Add code to the handler to retrieve information to populate the report fields.
The following example shows what the code for the method looks like.
To write the code in Visual Basic
Visual Basic.NET code. Paste INSIDE the FetchData event. |
Copy Code
|
If iEntry > pBM.Count - 1 Then
eArgs.EOF = True
Else
eArgs.EOF = False
iEntry += 1
End If
|
To write the code in C#
C# code. Paste INSIDE the FetchData event. |
Copy Code
|
if (iEntry > pBM.Count - 1)
{
eArgs.EOF = true;
}
else
{
eArgs.EOF = false;
iEntry += 1;
}
|
See Also